Skip to content

refactor: extract UnitsPage business logic into custom hook#10

Open
WesleyHuchit wants to merge 1 commit into
owlmaps:mainfrom
WesleyHuchit:refactor/units-page-component
Open

refactor: extract UnitsPage business logic into custom hook#10
WesleyHuchit wants to merge 1 commit into
owlmaps:mainfrom
WesleyHuchit:refactor/units-page-component

Conversation

@WesleyHuchit

@WesleyHuchit WesleyHuchit commented Jan 27, 2026

Copy link
Copy Markdown

…recated UnitsPage file.## 📋 Summary
Refactored the UnitsPage component to separate business logic from presentation, improving code organization and facilitating maintenance and testing.

🔄 Changes Made

File Structure

  • ✨ Created custom hook useUnitsPage in src/hooks/useUnitsPage.ts
  • 📁 Moved UnitsPage component from src/UnitsPage.tsx to src/pages/UnitsPage.tsx
  • 🔄 Updated App.tsx to import from the new path

Separation of Concerns

  • useUnitsPage Hook: Contains all business logic:

    • State management (loading, data, query, compact mode)
    • Filtering and search logic
    • Event handlers (query, compact mode, hamburger menu)
    • JSON data fetching
    • Base units generation for navigation
  • UnitsPage Component: Now focused solely on presentation:

    • UI rendering
    • HTML/JSX structure
    • Uses hook to obtain data and handlers

✅ Benefits

  • 🧹 Cleaner and more organized code
  • 🔄 Reusable logic that can be used in other components if needed
  • 🧪 Easier unit testing of hook and component separately
  • 📦 Better separation of concerns (presentation vs business logic)
  • 🗂️ More organized folder structure (pages/ and hooks/)

🧪 Testing

  • Verified that functionality remains the same
  • Page navigation working
  • Search filter working correctly
  • Compact mode working
  • Hamburger menu working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant